<style lang="less">
  @import './login.less';
</style>
<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
export default {
  components: {
    LoginForm
  },
  methods: {
    handleSubmit ({ userName, password }) {
      let data={
        username:userName,
        password:password,
        grant_type:"password",
        scope:"select",
        client_id:"client",
        client_secret:"client"
      }
      const msg = this.$Message.loading({
        content: '正在登陆，请稍后！！！',
        duration: 0
      });
           this.http.login("/oauth/token",this.qs.stringify(data)).then(res=>{
           if(res.data){
             this.$store.dispatch("setuser",userName)
             setTimeout(msg, 0);
             let token = res.data
             this.$store.dispatch("dosettoken",token)
           //  let authoritylist = []
       /*     res.data.authority.forEach(index=>{
               authoritylist.push(index.authority)
             })*/
        //     this.$store.commit("setAuthoritys",authoritylist)
             window.sessionStorage.setItem("token",token)
             this.$router.push({
               name: this.$config.homeName
             })
           }
         }).catch(res=>{
             setTimeout(msg, 0);
             this.$Modal.error({
               title: "登陆失败",
               content: "登陆失败！！！"
             });
           })
    }
  }
}
</script>

<style>

</style>
